import type { TagRecord } from '@/DatabaseType/Tag';
import type { PaginationConfig } from '@/types';
import { ServiceProxy } from '@/constant';
import type { RequestResult } from '@/utils/request';
import { request } from '@umijs/max';

// 获取角色列表
export async function getTagList(
  params: Partial<Pick<TagRecord, 'id' | 'name'>> & PaginationConfig,
): Promise<
  RequestResult<{
    total: number;
    list: TagRecord[];
  }>
> {
  return request(`${ServiceProxy.DefaultPrefix}/tag`, {
    method: 'GET',
    params,
  });
}

// 删除
export async function deleteTag(id: number): Promise<RequestResult<void>> {
  return request(`${ServiceProxy.DefaultPrefix}/tag/${id}`, {
    method: 'DELETE',
  });
}

// 更新
export async function updateTag(
  id: number,
  data: Pick<TagRecord, 'coverUrl' | 'name'>,
): Promise<RequestResult<void>> {
  return request(`${ServiceProxy.DefaultPrefix}/tag/${id}`, {
    method: 'PUT',
    data,
  });
}

// 创建
export async function addTag(
  data: Pick<TagRecord, 'coverUrl' | 'name'>,
): Promise<RequestResult<void>> {
  return request(`${ServiceProxy.DefaultPrefix}/tag`, {
    method: 'POST',
    data,
  });
}
